
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "Socket-Client.h"


int32_t CreaConexionclient_INET(char *direccionIP, char *puerto){

		int32_t Sock;
		struct sockaddr_in direccion;
		memset(&direccion, 0, sizeof(struct sockaddr_in));

		if((Sock = socket(AF_INET , SOCK_STREAM , 0))== -1)
		{
			printf ("error SOCKET");
			perror("socket");
		}
		direccion.sin_family= AF_INET;
		direccion.sin_addr.s_addr= inet_addr(direccionIP);
		direccion.sin_port = htons( atoi(puerto));

		while( connect(Sock,(struct sockaddr *) &direccion, sizeof(direccion))==-1);
	//	printf("Connect OK\n");
		return Sock;
}




int32_t CreaConexionclient_UXIT(void *pachUNIX)
{
	int32_t Sock;
	struct sockaddr_un  direccion;
	memset(&direccion, 0, sizeof(struct sockaddr_un));
	direccion.sun_family= AF_UNIX;
	strncpy(direccion.sun_path, pachUNIX, strlen(pachUNIX));

	if((Sock = socket(AF_UNIX, SOCK_STREAM, 0))== -1 )
		{
		printf ("error SOCKET\n");
		return -1;
		}

	while (connect(Sock,(struct sockaddr *)&direccion ,strlen (direccion.sun_path) + sizeof (direccion.sun_family) )==-1);
//	printf("Connect OK\n");
	return Sock;
}

